package com.hujing.exception.controller;

import com.hujing.exception.service.ExceptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private ExceptionService exceptionService;

    @GetMapping("/test")
    public void test(){
        exceptionService.handleException(new Exception("Test exception"));
        System.out.println("执行抛出异常后的方法");
    }

    @GetMapping("/test2")
    public void test2(){
        try {
            exceptionService.throwException(new Exception("Test exception"));
            System.out.println("执行抛出异常后的方法");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
